/**
 * jims
 */
package com.jims.master.modules.csm.web;

import com.jims.master.common.persistence.Page;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.common.web.BaseController;
import com.jims.master.modules.csm.entity.ExpStock;
import com.jims.master.modules.csm.service.ExpStockService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

/**
 * 过期消耗品统计Controller
 * @author DT
 * @version 2017-03-15
 */
@Controller
@RequestMapping(value = "${adminPath}/csm/expExpiredStatistics")
public class ExpExpiredStatisticsController extends BaseController {

	@Autowired
	private ExpStockService expStockService;
	@ModelAttribute
	public ExpStock get(@RequestParam(required=false) String id) {
		ExpStock entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = expStockService.get(id);
		}
		if (entity == null){
			entity = new ExpStock();
		}
		return entity;
	}

	@RequiresPermissions("user")
	@RequestMapping(value = {"index", ""})
	public String index(ExpStock expStock,HttpServletRequest request, HttpServletResponse response, Model model) {
        expStock.setExpireDate(new Date());
		Page<ExpStock> page=expStockService.findExpStock(new Page<ExpStock>(request, response), expStock);
		model.addAttribute("page",page);
		model.addAttribute("ExpStock",expStock);
		return "modules/csm/ExpExpiredStatistics";
	}

}